<?php defined('InNcPHP') or exit('Access Invalid!');?>

<script type="text/javascript" src="<?php echo RESOURCE_URL;?>/common/jquery-ui/jquery.ui.js"></script>
<script type="text/javascript" src="<?php echo RESOURCE_URL;?>/common/jquery-ui/i18n/zh-CN.js" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="<?php echo RESOURCE_URL;?>/common/jquery-ui/themes/ui-lightness/jquery.ui.css"  />

<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <h3><?php echo $lang['order_index'];?></h3>
            <?php echo $output['top_link'];?>
        </div>
    </div>
    <div class="fixed-empty"></div>
    <!--  搜索表单  -->
    <form method="get" name="formSearch" id="formSearch">
        <input type="hidden" value="order_doconsume" name="act">
        <input type="hidden" value="index" name="op">
        <table class="tb-type1 noborder search">
            <tbody>
            <tr>
                <th><label> 订单核销码</label></th>
                <td><input type="text" name="search_sn" value="<?php echo $output['search']['search_sn']; ?>" class="txt"></td>
                <td>
                    <a href="javascript:void(0);" onclick="$('#formSearch').submit();" class="btn-search"></a>
                    <?php if ($output['search']['search_sn'] || $output['search']['search_stime'] || $output['search']['search_etime'] || $output['search']['search_merchant'] || $output['search']['search_status']): ?>
                        <a href="index.php?act=order_doconsume&op=index" class="btns "><span><?php echo $lang['nc_cancel_search']?></span></a>
                    <?php endif; ?>
                </td>
            </tr>
            </tbody>
        </table>
    </form>
    <!--  显示列表  -->
    <table class="table tb-type2 nobdb">
        <thead>
        <tr class="thead">
            <th><?php echo $lang['order_index_order_sn']?></th>
            <th class="align-center"><?php echo $lang['order_index_title']?></th>
            <th class="align-center"><?php echo $lang['order_index_nickname']?></th>
            <th><?php echo $lang['order_index_content']?></th>
            <th class="align-center"><?php echo $lang['order_index_merchant']?></th>
            <th class="align-center">订单类型</th>
            <th class="align-center"><?php echo $lang['order_index_money']; ?></th>
            <th class="align-center"><?php echo $lang['order_index_addtime'];?></th>
            <th class="align-center"><?php echo $lang['order_index_status']?></th>
            <th class="align-center"><?php echo $lang['nc_handle'];?></th>
        </tr>
        <tbody>
        <?php if(!empty($output['orders']) && is_array($output['orders'])){ ?>
            <?php foreach($output['orders'] as $k => $v){ ?>
                <tr class="hover member">
                    <td><?php echo $v['order_sn']; ?></td>
                    <td class="align-center" style="width:200px;overflow: hidden; white-space: nowrap; text-overflow: ellipsis;display: block; "><?php echo $v['ticket_title']; ?></td>
                    <td class="align-center"><?php echo $v['mobile']; ?></td>
                    <td >
                        <?php foreach ($v['sku'] as $sku): ?>
                            <?php if($v['order_type']==2) {?>
                                <?php echo $sku['type_name'].'x'.$sku['ot_num'].';'; ?>
                            <?php }elseif($v['order_type']==1){?>
                                <?php echo $v['spec_name'].'x'.$sku['oh_num'].';'; ?>
                            <?php }else{ ?>
                                <span style="width:200px;overflow: hidden; white-space: nowrap; text-overflow: ellipsis;display: block; "><?php echo $v['spec_name'] ?></span>x<span><?php echo $sku['og_num']; ?></span>
                            <?php } ?>
                        <?php endforeach; ?>
                    </td>
                    <td class="align-center"><?php echo $v['mc_shop_name']; ?></td>
                    <td class="align-center"><?php echo $output['order_type'][$v['order_type']]; ?></td>
                    <td class="align-center"><?php echo $v['need_pay']; ?></td>
                    <td class="align-center"><?php echo date('Y-m-d H:i:s',$v['add_time']); ?></td>
                    <td class="align-center"><?php echo $output['status'][$v['order_status']]; ?></td>
                    <td class="align-center">
                        <a href="index.php?act=order&op=detail&order_id=<?php echo $v['order_id']; ?>">查看</a>
                        <?php if ($v['order_status'] == 20): ?>
                            <a href="###" onclick="check_money('<?php echo $v['ticket_code']; ?>', $(this));">核销</a>
                        <?php endif; ?>
                    </td>/
                </tr>
            <?php } ?>
        <?php }else { ?>
            <tr class="no_data">
                <td colspan="11"><?php echo $lang['nc_no_record']?></td>
            </tr>
        <?php } ?>
        </tbody>
        <tfoot class="tfoot">
        <?php if(!empty($output['orders']) && is_array($output['orders'])){ ?>
            <tr>
                <td colspan="16">
                    <div class="pagination"> <?php echo $output['page'];?> </div>
                </td>
            </tr>
        <?php } ?>
        </tfoot>
    </table>
</div>
<script>
    //开始日期
    $('#search_stime').datepicker({
        dateFormat: 'yy-mm-dd',
        onClose: function(selectedDate) {
            $("#search_etime").datepicker("option", "minDate", selectedDate);
        }
    });
    //结束日期
    $('#search_etime').datepicker({
        dateFormat: 'yy-mm-dd',
        onClose: function(selectedDate) {
            $("#search_stime").datepicker("option", "maxDate", selectedDate);
        }
    });
    //确认收款
    function check_money(ticket_code, obj) {
        layer.confirm('确认核销该订单?', {
            btn: ['<?php echo $lang['nc_yes']; ?>', '<?php echo $lang['nc_no']; ?>']
        }, function (index) {
            $.post('index.php?act=order_doconsume&op=consume', {ticket_code:ticket_code},function (data) {
                if (data.ecode==1) {
                    obj.parent().prev().text('<?php echo $output['status']['21']; ?>');
                    obj.remove();
                    layer.alert('核销成功');
                } else {
                    layer.alert(data.msgs);
                }
                layer.close(index);
            }, 'json');
        });
    }
</script>
